home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
010
/
blit.arc
/
PLOT.C
< prev
next >
Wrap
Text File
|
1985-05-09
|
9KB
|
357 lines
/* PLOT/ADDBIT.C @FINEN */
/*
* FILE: ADDBIT.C
*
* SCCS-ID: @(#)ADDBIT.C 1.5 85/03/24
*
* DESCRIPTION: THIS FILE CONTAINS THE ONE FUNCTION ADDBIT WHICH
* ADDS A BIT ONTO THE END OF THE CURRENT PLOT LINE.
*
* AUTHOR: SIMON KENYON.
*
* HISTORY: SCK 1.1 83/10/03 CREATED.
* SCK 1.2 84/11/29 MADE IT WORK.
* SCK 1.3 85/03/04 TIDIED UP FOR RELEASE.
* SCK 1.4 85/03/22 FIXED UP GLOBAL VARIABLE DECLARATIONS.
* SCK 1.5 85/03/24 CHANGED THE INCLUDE FILES AROUND.
*/
#INCLUDE "LAYERS.H"
EXTERN INT BITPTR;
UNSIGNED SHORT LINE[512];
UNSIGNED SHORT WORDMASK[] = {
0X8000, 0X4000, 0X2000, 0X1000,
0X0800, 0X0400, 0X0200, 0X0100,
0X0080, 0X0040, 0X0020, 0X0010,
0X0008, 0X0004, 0X0002, 0X0001
};
/*
* NAME: ADDBIT
*
* DESCRIPTION: ADD A BIT ONTO THE END OF THE CURRENT PLOT LINE.
*
* SYNOPSIS: ADDBIT (BIT)
* INT BIT;
*
* GLOBALS: BITPTR (R/W)
* LINE (W)
* WORDMASK (R)
*
* CALLS: NOTHING.
*
* CALLED BY: APPEND (APPEND.C)
*/
ADDBIT (BIT)
INT BIT; /* 0 OR 1 */
{
INT WORDIDX;
INT BITIDX;
WORDIDX = BITPTR / WORDSIZE;
BITIDX = BITPTR % WORDSIZE;
IF (BIT)
LINE[WORDIDX] |= WORDMASK[BITIDX];
ELSE
LINE[WORDIDX] &= ~WORDMASK[BITIDX];
BITPTR++;
}
/* PLOT/APPEND.C @FINEN */
/*
* FILE: APPEND.C
*
* SCCS-ID: @(#)APPEND.C 1.4 85/03/24
*
* DESCRIPTION: THIS FILE CONTAINS THE ONE FUNCTION APPEND WHICH
* ADDS SOME MORE BITS TO THE END OF THE PLOT LINE.
*
* AUTHOR: SIMON KENYON.
*
* HISTORY: SCK 1.1 83/10/03 CREATED.
* SCK 1.2 84/11/29 MADE IT WORK.
* SCK 1.3 85/03/04 TIDIED UP FOR RELEASE.
* SCK 1.4 85/03/24 CHANGED THE INCLUDE FILES AROUND.
*/
#INCLUDE "LAYERS.H"
/*
* NAME: APPEND
*
* DESCRIPTION: ADD SOME MORE BITS TO THE END OF THE PLOT LINE.
*
* SYNOPSIS: APPEND (BITS, START, END, SIZE)
* UNSIGNED SHORT BITS;
* INT START;
* INT END;
* INT SIZE;
*
* GLOBALS: NONE.
*
* CALLS: ADDBIT (ADDBIT.C)
*
* CALLED BY: PLOT (PLOT.C)
*/
APPEND (BITS, START, END, SIZE)
UNSIGNED SHORT BITS;
INT START;
INT END;
INT SIZE;
{
INT I;
INT J;
FOR (I = START; I <= END; I++)
FOR (J = 0; J < SIZE; J++)
IF (BITS & (1 << (WORDSIZE - (I + 1))))
ADDBIT (1);
ELSE
ADDBIT (0);
}
/* PLOT/PLOT.C @FINEN */
/*
* FILE: PLOT.C
*
* SCCS-ID: @(#)PLOT.C 1.4 85/03/24
*
* DESCRIPTION: THIS FILE CONTAINS THE ONE FUNCTION PLOT, WHICH
* GIVEN A BITMAP SB, A RECTANGLE R AND A SCALE FACTOR SIZE
* CREATE A PLOT FILE SUITABLE FOR THE PRINTRONIX.
*
* AUTHOR: SIMON KENYON.
*
* HISTORY: SCK 1.1 83/10/03 CREATED.
* SCK 1.2 84/11/29 MADE IT WORK.
* SCK 1.3 85/02/22 TIDIED UP FOR RELEASE.
* SCK 1.4 85/03/24 CHANGED THE INCLUDE FILES AROUND.
*/
#INCLUDE <STDIO.H>
#INCLUDE "LAYERS.H"
INT BITPTR; /* BIT POINTER INTO SCAN LINE BEING
CONSTRUCTED */
/*
* NAME: PLOT
*
* DESCRIPTION: GIVEN A BITMAP SB, A RECTANGLE R AND A SCALE FACTOR SIZE
* CREATE A PLOT FILE SUITABLE FOR THE PRINTRONIX.
*
* SYNOPSIS: PLOT (SB, R, SIZE)
* STRUCT BITMAP *SB;
* STRUCT RECTANGLE R;
* INT SIZE;
*
* GLOBALS: BITPTR (W)
*
* CALLS: PRINTF (LIBC)
* APPEND (APPEND.C)
* REFORMAT (REFORMAT.C)
* OUTLINE (OUTLINE.C)
*
* CALLED BY: THIS IS A TOP LEVEL FUNCTION.
*/
PLOT (SB, R, SIZE)
STRUCT BITMAP *SB;
STRUCT RECTANGLE R;
INT SIZE;
{
INT INDEX;
INT DELTA;
INT SX;
INT SY;
INT DX;
INT DY;
INT W;
INT H;
INT STARTBITS;
INT ENDBITS;
INT START;
INT END;
INT WORD;
INT NWORDS;
INT SCANLINE;
INT LINECOUNT;
UNSIGNED SHORT SRCWORD;
W = R.CORNER.X - R.ORIGIN.X;
H = R.CORNER.Y - R.ORIGIN.Y;
IF ((W <= 0) || (H <= 0))
RETURN;
SX = R.ORIGIN.X;
SY = R.ORIGIN.Y;
STARTBITS = SX % WORDSIZE;
ENDBITS = (SX + W - 1) % WORDSIZE;
IF (W <= (WORDSIZE - STARTBITS))
NWORDS = 1;
ELSE
NWORDS = (W - (WORDSIZE - STARTBITS) - 1) / WORDSIZE + 2;
INDEX = (SY - SB -> RECT.ORIGIN.Y) * SB -> WIDTH +
(SX / WORDSIZE) -
(SB -> RECT.ORIGIN.X / WORDSIZE);
DELTA = SB -> WIDTH - NWORDS;
/*
* GUNGE AT START OF PLOTFILE
*/
PRINTF ("\N\N\N");
FOR (SCANLINE = 1; SCANLINE <= H; SCANLINE++) {
/*
* GUNGE AT START OF PLOT LINE
*/
BITPTR = 0;
START = STARTBITS;
END = WORDSIZE - 1;
FOR (WORD = 1; WORD <= NWORDS; WORD++) {
SRCWORD = *(SB -> BASE + INDEX);
APPEND (SRCWORD, START, END, SIZE);
INDEX++;
IF (WORD == (NWORDS - 1)) {
START = 0;
END = ENDBITS;
}
ELSE {
START = 0;
END = WORDSIZE - 1;
}
}
/*
* GUNGE AT END OF LINE
*/
APPEND ((SHORT) 0, 0, 15, 1); /* KLUDGE (I'M SORRY) */
REFORMAT ();
FOR (LINECOUNT = 0; LINECOUNT < SIZE; LINECOUNT++)
OUTLINE ();
INDEX += DELTA;
}
}
/* PLOT/OUTLINE.C @FINEN */
/*
* FILE: OUTLINE.C
*
* SCCS-ID: @(#)OUTLINE.C 1.4 85/03/24
*
* DESCRIPTION: THIS FILE CONTAINS THE ONE FUNCTION OUTLINE WHICH
* SENDS THE NEXT OUTPUT LINE TO THE PRINTRONIX PLOTTER.
*
* AUTHOR: SIMON KENYON.
*
* HISTORY: SCK 1.1 83/10/03 CREATED.
* SCK 1.2 84/11/29 MADE IT WORK.
* SCK 1.3 85/03/04 TIDIED UP FOR RELEASE.
* SCK 1.4 85/03/24 CHANGED THE INCLUDE FILES AROUND.
*/
#INCLUDE <STDIO.H>
#INCLUDE "LAYERS.H"
EXTERN INT OUTPTR;
EXTERN UNSIGNED CHAR OUTLIN[];
/*
* NAME: OUTLINE
*
* DESCRIPTION: SEND THE NEXT OUTPUT LINE TO THE PRINTRONIX PLOTTER.
*
* SYNOPSIS: OUTLINE ()
*
* GLOBALS: OUTPTR (R)
* OUTLIN (R)
*
* CALLS: PRINTF (LIBC)
*
* CALLED BY: PLOT (PLOT.C)
*/
OUTLINE ()
{
INT I;
FOR (I = 0; I < (OUTPTR / BYTESIZE); I++)
PRINTF ("%C", OUTLIN[I]);
PRINTF ("\N");
}
/* PLOT/REFORMAT.C @FINEN */
/*
* FILE: REFORMAT.C
*
* SCCS-ID: @(#)REFORMAT.C 1.4 85/03/24
*
* DESCRIPTION: THIS FILE CONTAINS ONE ROUTINE REFORMAT WHICH
* DIDDLES THE BITS IN A PLOT LINE SO THAT THE
* PRINTRONIX PRINTER/PLOTTER UNDERSTANDS THEM.
*
* AUTHOR: SIMON KENYON.
*
* HISTORY: SCK 1.1 83/10/03 CREATED.
* SCK 1.2 84/11/29 MADE IT WORK.
* SCK 1.3 85/03/04 TIDIED UP FOR RELEASE.
* SCK 1.4 85/03/24 CHANGED THE INCLUDE FILES AROUND.
*/
#INCLUDE "LAYERS.H"
EXTERN INT BITPTR;
EXTERN UNSIGNED SHORT LINE[];
EXTERN UNSIGNED SHORT WORDMASK[];
UNSIGNED SHORT BYTEMASK[] = {
0X80, 0X40, 0X20, 0X10,
0X08, 0X04, 0X02, 0X01
};
UNSIGNED CHAR OUTLIN[1024];
INT OUTPTR;
/*
* NAME: REFORMAT
*
* DESCRIPTION: DIDDLE THE BITS IN A PLOT LINE SO THAT THE
* PRINTRONIX PRINTER/PLOTTER UNDERSTANDS THEM.
*
* SYNOPSIS: REFORMAT ()
*
* GLOBALS: BITPTR (R)
* LINE (R)
* WORDMASK (R)
* BYTEMASK (R)
* OUTLIN (W)
* OUTPTR (R/W)
*
* CALLS: NOTHING.
*
* CALLED BY: PLOT (PLOT.C)
*/
REFORMAT ()
{
INT I;
/*
* NOTE THAT BECAUSE THIS CODE RUNS UNDER PRIMOS
* THE TOP BIT OF EACH BYTE IS BEING SET
*/
OUTLIN[0] = 0X85; /* THAT'S WHAT THE MAN SAID */
OUTPTR = 15;
FOR (I = 0; I < BITPTR; I++) {
IF (LINE[I / WORDSIZE] & WORDMASK[I % WORDSIZE])
OUTLIN[OUTPTR / BYTESIZE] |= BYTEMASK[OUTPTR % BYTESIZE];
ELSE
OUTLIN[OUTPTR / BYTESIZE] &= ~BYTEMASK[OUTPTR % BYTESIZE];
IF ((OUTPTR % BYTESIZE) == 2) {
OUTLIN[OUTPTR / BYTESIZE] |= 0XC0;
OUTPTR += 13; /* LEFT AS AN EXERCISE TO THE READER */
}
ELSE
OUTPTR--;
}
}